home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / text / edit / rexx-mode1_1.lha / rexx-mode / rexx-mode.el < prev    next >
Lisp/Scheme  |  2001-03-07  |  25KB  |  682 lines

  1. ;;;
  2. ;;; FILE
  3. ;;;    rexx-mode.el    V1.1
  4. ;;;
  5. ;;;    Copyright (C) 1993 by Anders Lindgren.
  6. ;;;
  7. ;;;    This file is NOT part of GNU Emacs (yet).
  8. ;;;
  9. ;;;
  10. ;;; DISTRIBUTION
  11. ;;;    REXX-mode is free software; you can redistribute it and/or modify
  12. ;;;    it under the terms of the GNU General Public License as published 
  13. ;;;    by the Free Software Foundation; either version 1, or (at your 
  14. ;;;    option) any later version.
  15. ;;;
  16. ;;;    GNU Emacs is distributed in the hope that it will be useful,
  17. ;;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ;;;    GNU General Public License for more details.
  20. ;;;
  21. ;;;    You should have received a copy of the GNU General Public
  22. ;;;    License along with GNU Emacs; see the file COPYING.  If not,
  23. ;;;    write to the Free Software Foundation, 675 Mass Ave, Cambridge,
  24. ;;;    MA 02139, USA.
  25. ;;;
  26. ;;;
  27. ;;; AUTHOR
  28. ;;;    Anders Lindgren, d91ali@csd.uu.se
  29. ;;;
  30. ;;;         Abbrevationtable due to:
  31. ;;;    Johan Bergkvist, nv91-jbe@nada.kth.se
  32. ;;;
  33. ;;;         Font locking due to:
  34. ;;;     James Perrin, james.perrin@ntlworld.com
  35. ;;;
  36. ;;;
  37. ;;; USAGE
  38. ;;;    This file contains code for a GNU Emacs major mode for
  39. ;;;    editing REXX program files.
  40. ;;;
  41. ;;;     Type C-h m in Emacs for information on how to configurate
  42. ;;;    the rexx-mode, or see rexx-mode.doc.
  43. ;;;
  44. ;;;    Put the following lines into your .emacs and rexx-mode
  45. ;;;    will be automatically loaded when editing a REXX program.
  46. ;;;    If rexx-mode shall be used for files with other extensions
  47. ;;;    you can create more (cons ...) lines with these extensions.
  48. ;;;
  49. ;;;    (autoload 'rexx-mode "rexx-mode" "REXX mode" nil t)
  50. ;;;    (setq auto-mode-alist
  51. ;;;          (append
  52. ;;;           (list (cons "\\.rexx$"  'rexx-mode)
  53. ;;;             (cons "\\.elx$"   'rexx-mode)
  54. ;;;             (cons "\\.ncomm$" 'rexx-mode)
  55. ;;;             (cons "\\.cpr$"   'rexx-mode)
  56. ;;;                    )
  57. ;;;           auto-mode-alist))
  58. ;;;
  59. ;;; HISTORY
  60. ;;;    93-01-07 V0.1 ALi    Works for the first time.
  61. ;;;    92-01-11 V0.2 ALi    rexx-calc-indent totally rewritten.
  62. ;;;     93-03-08 V0.3 JB        rexx-indent-and-newline-and-indent added.
  63. ;;;                             Abbrev-table containing 173 entries created.
  64. ;;;                             rexx-check-expansion added.
  65. ;;;                             rexx-mode enables use of abbrev-table.
  66. ;;;    93-03-15 V0.4 ALi    abbrev-mode removed, better to call
  67. ;;;                 (abbrev-mode 1) from the hook.
  68. ;;;                case-fold-search set to t to recognize capital
  69. ;;;                 letters in keywords.
  70. ;;;                Old (setq case-fold-search nil) removed which
  71. ;;;                 prevented the recognition of END.
  72. ;;;                rexx-indent-and-newline-and-indent renamed to
  73. ;;;                 rexx-indent-newline-indent.
  74. ;;;                rexx-i-n-i now only expands abbrevs when
  75. ;;;                 buffer is in abbrev-mode.
  76. ;;;                New rexx-newline-and-indent added.
  77. ;;;    93-03-20      ALi     A serious bug in the routine for checking
  78. ;;;                strings and comments found and fixed.
  79. ;;;                              V1.0 Relesed!    
  80. ;;;
  81. ;;;     01-01-01 V1.1 JP         font-lock support added
  82. ;;;
  83.  
  84.  
  85. (provide 'rexx-mode)
  86. (autoload 'rexx-debug "rexx-debug" "REXX source level debugger" t)
  87.  
  88. (defconst rexx-indent 2
  89.   "*This variable contains the indentation in rexx-mode.")
  90.  
  91. (defconst rexx-end-indent 0
  92.   "*This variable indicates the relative position of the \"end\" in REXX mode.")
  93.  
  94. (defconst rexx-cont-indent 2
  95.   "*This variable indicates how far a continued line shall be intended.")
  96.  
  97. (defconst rexx-comment-col 32
  98.   "*This variable gives the desired comment column 
  99. for comments to the right of text.")
  100.  
  101. (defconst rexx-tab-always-indent t
  102.   "*Non-nil means TAB in REXX mode should always reindent the current line,
  103. regardless of where in the line point is when the TAB command is used.")
  104.  
  105. (defconst rexx-special-regexp 
  106.   ".*\\(,\\|then\\|else\\)[ \t]*\\(/\\*.*\\*/\\)?[ \t]*$"
  107.   "*Regular expression for parsing lines which shall be followed by
  108. a extra indention")
  109.  
  110. (defvar rexx-mode-map nil
  111.   "Keymap for rexx-mode.")
  112. (if rexx-mode-map
  113.     nil
  114.   (setq rexx-mode-map (make-sparse-keymap))
  115.   (define-key rexx-mode-map "\t"   'rexx-indent-command)
  116.   (define-key rexx-mode-map "\177" 'backward-delete-char-untabify)
  117.   (define-key rexx-mode-map "\C-c\C-p" 'rexx-find-matching-do)
  118.   (define-key rexx-mode-map "\C-c\C-c" 'rexx-debug)
  119.   )
  120.  
  121. (defvar rexx-mode-syntax-table nil
  122.   "Syntax table in use in REXX-mode buffers.")
  123.  
  124. (if rexx-mode-syntax-table
  125.     ()
  126.   (setq rexx-mode-syntax-table (make-syntax-table))
  127.   (modify-syntax-entry ?\\ "\\" rexx-mode-syntax-table)
  128.   (modify-syntax-entry ?/ ". 14" rexx-mode-syntax-table)
  129.   (modify-syntax-entry ?* ". 23" rexx-mode-syntax-table)
  130.   (modify-syntax-entry ?+ "." rexx-mode-syntax-table)
  131.   (modify-syntax-entry ?- "." rexx-mode-syntax-table)
  132.   (modify-syntax-entry ?= "." rexx-mode-syntax-table)
  133.   (modify-syntax-entry ?% "." rexx-mode-syntax-table)
  134.   (modify-syntax-entry ?< "." rexx-mode-syntax-table)
  135.   (modify-syntax-entry ?> "." rexx-mode-syntax-table)
  136.   (modify-syntax-entry ?& "." rexx-mode-syntax-table)
  137.   (modify-syntax-entry ?| "." rexx-mode-syntax-table)
  138.   (modify-syntax-entry ?\' "\"" rexx-mode-syntax-table))
  139.  
  140. (defvar rexx-mode-abbrev-table nil
  141.   "*Abbrev table in use in rexx-mode buffers.")
  142.  
  143. (if rexx-mode-abbrev-table
  144.     nil
  145.   (define-abbrev-table 'rexx-mode-abbrev-table '(
  146.      ("address" "ADDRESS" rexx-check-expansion 0)
  147.      ("arg" "ARG" rexx-check-expansion 0)
  148.      ("break" "BREAK" rexx-check-expansion 0)
  149.      ("call" "CALL" rexx-check-expansion 0)
  150.      ("do" "DO" rexx-check-expansion 0)
  151.      ("drop" "DROP" rexx-check-expansion 0)
  152.      ("echo" "ECHO" rexx-check-expansion 0)
  153.      ("else" "ELSE" rexx-check-expansion 0)
  154.      ("end" "END" rexx-check-expansion 0)
  155.      ("exit" "EXIT" rexx-check-expansion 0)
  156.      ("if" "IF" rexx-check-expansion 0)
  157.      ("interpret" "INTERPRET" rexx-check-expansion 0)
  158.      ("iterate" "ITERATE" rexx-check-expansion 0)
  159.      ("leave" "LEAVE" rexx-check-expansion 0)
  160.      ("nop" "NOP" rexx-check-expansion 0)
  161.      ("numeric" "NUMERIC" rexx-check-expansion 0)
  162.      ("options" "OPTIONS" rexx-check-expansion 0)
  163.      ("otherwise" "OTHERWISE" rexx-check-expansion 0)
  164.      ("parse" "PARSE" rexx-check-expansion 0)
  165.      ("procedure" "PROCEDURE" rexx-check-expansion 0)
  166.      ("pull" "PULL" rexx-check-expansion 0)
  167.      ("push" "PUSH" rexx-check-expansion 0)
  168.      ("queue" "QUEUE" rexx-check-expansion 0)
  169.      ("return" "RETURN" rexx-check-expansion 0)
  170.      ("say" "SAY" rexx-check-expansion 0)
  171.      ("select" "SELECT" rexx-check-expansion 0)
  172.      ("shell" "SHELL" rexx-check-expansion 0)
  173.      ("signal" "SIGNAL" rexx-check-expansion 0)
  174.      ("then" "THEN" rexx-check-expansion 0)
  175.      ("trace" "TRACE" rexx-check-expansion 0)
  176.      ("upper" "UPPER" rexx-check-expansion 0)
  177.      ("when" "WHEN" rexx-check-expansion 0)
  178.      ("value" "VALUE" rexx-check-expansion 0)
  179.      ("to" "TO" rexx-check-expansion 0)
  180.      ("by" "BY" rexx-check-expansion 0)
  181.      ("for" "FOR" rexx-check-expansion 0)
  182.      ("forever" "FOREVER" rexx-check-expansion 0)
  183.      ("while" "WHILE" rexx-check-expansion 0)
  184.      ("until" "UNTIL" rexx-check-expansion 0)
  185.      ("form" "FORM" rexx-check-expansion 0)
  186.      ("digits" "DIGITS" rexx-check-expansion 0)
  187.      ("fuzz" "FUZZ" rexx-check-expansion 0)
  188.      ("scientific" "SCIENTIFIC" rexx-check-expansion 0)
  189.      ("engineering" "ENGINEERING" rexx-check-expansion 0)
  190.      ("failat" "FAILAT" rexx-check-expansion 0)
  191.      ("prompt" "PROMPT" rexx-check-expansion 0)
  192.      ("results" "RESULTS" rexx-check-expansion 0)
  193.      ("upper" "UPPER" rexx-check-expansion 0)
  194.      ("external" "EXTERNAL" rexx-check-expansion 0)
  195.      ("source" "SOURCE" rexx-check-expansion 0)
  196.      ("with" "WITH" rexx-check-expansion 0)
  197.      ("command" "COMMAND" rexx-check-expansion 0)
  198.      ("function" "FUNCTION" rexx-check-expansion 0)
  199.      ("var" "VAR" rexx-check-expansion 0)
  200.      ("version" "VERSION" rexx-check-expansion 0)
  201.      ("expose" "EXPOSE" rexx-check-expansion 0)
  202.      ("on" "ON" rexx-check-expansion 0)
  203.      ("off" "OFF" rexx-check-expansion 0)
  204.      ("abbrev" "ABBREV" rexx-check-expansion 0)
  205.      ("abs" "ABS" rexx-check-expansion 0)
  206.      ("addlib" "ADDLIB" rexx-check-expansion 0)
  207.      ("b2c" "B2C" rexx-check-expansion 0)
  208.      ("bitand" "BITAND" rexx-check-expansion 0)
  209.      ("bitchg" "BITCHG" rexx-check-expansion 0)
  210.      ("bitclr" "BITCLR" rexx-check-expansion 0)
  211.      ("bitcomp" "BITCOMP" rexx-check-expansion 0)
  212.      ("bitor" "BITOR" rexx-check-expansion 0)
  213.      ("bittst" "BITTST" rexx-check-expansion 0)
  214.      ("bitset" "BITSET" rexx-check-expansion 0)
  215.      ("c2b" "C2B" rexx-check-expansion 0)
  216.      ("c2d" "C2D" rexx-check-expansion 0)
  217.      ("c2x" "C2X" rexx-check-expansion 0)
  218.      ("center" "CENTER" rexx-check-expansion 0)
  219.      ("centre" "CENTRE" rexx-check-expansion 0)
  220.      ("close" "CLOSE" rexx-check-expansion 0)
  221.      ("compress" "COMPRESS" rexx-check-expansion 0)
  222.      ("compare" "COMPARE" rexx-check-expansion 0)
  223.      ("copies" "COPIES" rexx-check-expansion 0)
  224.      ("d2c" "D2C" rexx-check-expansion 0)
  225.      ("datatype" "DATATYPE" rexx-check-expansion 0)
  226.      ("delstr" "DELSTR" rexx-check-expansion 0)
  227.      ("delword" "DELWORD" rexx-check-expansion 0)
  228.      ("eof" "EOF" rexx-check-expansion 0)
  229.      ("errortext" "ERRORTEXT" rexx-check-expansion 0)
  230.      ("exists" "EXISTS" rexx-check-expansion 0)
  231.      ("export" "EXPORT" rexx-check-expansion 0)
  232.      ("freespace" "FREESPACE" rexx-check-expansion 0)
  233.      ("getclip" "GETCLIP" rexx-check-expansion 0)
  234.      ("getspace" "GETSPACE" rexx-check-expansion 0)
  235.      ("hash" "HASH" rexx-check-expansion 0)
  236.      ("import" "IMPORT" rexx-check-expansion 0)
  237.      ("index" "INDEX" rexx-check-expansion 0)
  238.      ("insert" "INSERT" rexx-check-expansion 0)
  239.      ("lastpos" "LASTPOS" rexx-check-expansion 0)
  240.      ("left" "LEFT" rexx-check-expansion 0)
  241.      ("length" "LENGTH" rexx-check-expansion 0)
  242.      ("max" "MAX" rexx-check-expansion 0)
  243.      ("min" "MIN" rexx-check-expansion 0)
  244.      ("open" "OPEN" rexx-check-expansion 0)
  245.      ("overlay" "OVERLAY" rexx-check-expansion 0)
  246.      ("pos" "POS" rexx-check-expansion 0)
  247.      ("pragma" "PRAGMA" rexx-check-expansion 0)
  248.      ("random" "RANDOM" rexx-check-expansion 0)
  249.      ("randu" "RANDU" rexx-check-expansion 0)
  250.      ("readch" "READCH" rexx-check-expansion 0)
  251.      ("readln" "READLN" rexx-check-expansion 0)
  252.      ("remlib" "REMLIB" rexx-check-expansion 0)
  253.      ("reverse" "REVERSE" rexx-check-expansion 0)
  254.      ("right" "RIGHT" rexx-check-expansion 0)
  255.      ("seek" "SEEK" rexx-check-expansion 0)
  256.      ("setclip" "SETCLIP" rexx-check-expansion 0)
  257.      ("show" "SHOW" rexx-check-expansion 0)
  258.      ("sign" "SIGN" rexx-check-expansion 0)
  259.      ("space" "SPACE" rexx-check-expansion 0)
  260.      ("storage" "STORAGE" rexx-check-expansion 0)
  261.      ("strip" "STRIP" rexx-check-expansion 0)
  262.      ("substr" "SUBSTR" rexx-check-expansion 0)
  263.      ("subword" "SUBWORD" rexx-check-expansion 0)
  264.      ("symbol" "SYMBOL" rexx-check-expansion 0)
  265.      ("time" "TIME" rexx-check-expansion 0)
  266.      ("trace" "TRACE" rexx-check-expansion 0)
  267.      ("translate" "TRANSLATE" rexx-check-expansion 0)
  268.      ("trim" "TRIM" rexx-check-expansion 0)
  269.      ("verify" "VERIFY" rexx-check-expansion 0)
  270.      ("word" "WORD" rexx-check-expansion 0)
  271.      ("wordindex" "WORDINDEX" rexx-check-expansion 0)
  272.      ("wordlength" "WORDLENGTH" rexx-check-expansion 0)
  273.      ("words" "WORDS" rexx-check-expansion 0)
  274.      ("writech" "WRITECH" rexx-check-expansion 0)
  275.      ("writeln" "WRITELN" rexx-check-expansion 0)
  276.      ("x2c" "X2C" rexx-check-expansion 0)
  277.      ("xrange" "XRANGE" rexx-check-expansion 0)
  278.      ("allocmem" "ALLOCMEM" rexx-check-expansion 0)
  279.      ("baddr" "BADDR" rexx-check-expansion 0)
  280.      ("bitxor" "BITXOR" rexx-check-expansion 0)
  281.      ("break_c" "BREAK_C" rexx-check-expansion 0)
  282.      ("break_d" "BREAK_D" rexx-check-expansion 0)
  283.      ("break_e" "BREAK_E" rexx-check-expansion 0)
  284.      ("break_f" "BREAK_F" rexx-check-expansion 0)
  285.      ("cache" "CACHE" rexx-check-expansion 0)
  286.      ("closeport" "CLOSEPORT" rexx-check-expansion 0)
  287.      ("d2x" "D2X" rexx-check-expansion 0)
  288.      ("date" "DATA" rexx-check-expansion 0)
  289.      ("delay" "DELAY" rexx-check-expansion 0)
  290.      ("delete" "DELETE" rexx-check-expansion 0)
  291.      ("error" "ERROR" rexx-check-expansion 0)
  292.      ("failure" "FAILURE" rexx-check-expansion 0)
  293.      ("find" "FIND" rexx-check-expansion 0)
  294.      ("forbid" "FORBID" rexx-check-expansion 0)
  295.      ("freemem" "FREEMEM" rexx-check-expansion 0)
  296.      ("getarg" "GETARG" rexx-check-expansion 0)
  297.      ("getpkt" "GETPKT" rexx-check-expansion 0)
  298.      ("halt" "HALT" rexx-check-expansion 0)
  299.      ("ioerr" "IOERR" rexx-check-expansion 0)
  300.      ("lines" "LINES" rexx-check-expansion 0)
  301.      ("makedir" "MAKEDIR" rexx-check-expansion 0)
  302.      ("next" "NEXT" rexx-check-expansion 0)
  303.      ("novalue" "NOVALUE" rexx-check-expansion 0)
  304.      ("null" "NULL" rexx-check-expansion 0)
  305.      ("offset" "OFFSET" rexx-check-expansion 0)
  306.      ("openport" "OPENPORT" rexx-check-expansion 0)
  307.      ("permit" "PERMIT" rexx-check-expansion 0)
  308.      ("rename" "RENAME" rexx-check-expansion 0)
  309.      ("reply" "REPLY" rexx-check-expansion 0)
  310.      ("showdir" "SHOWDIR" rexx-check-expansion 0)
  311.      ("showlist" "SHOWLIST" rexx-check-expansion 0)
  312.      ("sourceline" "SOURCELINE" rexx-check-expansion 0)
  313.      ("statef" "STATEF" rexx-check-expansion 0)
  314.      ("syntax" "SYNTAX" rexx-check-expansion 0)
  315.      ("trunc" "TRUNC" rexx-check-expansion 0)
  316.      ("typepkt" "TYPEPKT" rexx-check-expansion 0)
  317.      ("waitpkt" "WAITPKT" rexx-check-expansion 0)
  318.      ("x2d" "X2D" rexx-check-expansion 0))))
  319.  
  320.  
  321.  
  322. ;; font-lock patterns
  323. (defvar rexx-font-lock-keywords nil
  324.  "Expressions to highlight in V code mode")
  325.  
  326. (defvar rexx-font-lock-keywords-1 nil
  327.  "Level 1 expressions to highlight in V code mode")
  328.  
  329. (defvar rexx-font-lock-keywords-2 nil
  330.  "Level 2 expressions to highlight in V code mode")
  331.  
  332. (defvar rexx-font-lock-keywords-3 nil
  333.  "Level 3 expressions to highlight in V code mode")
  334.  
  335.  
  336. ;; Level 1 - comments and strings
  337. (setq rexx-font-lock-keywords-1 nil
  338. ;  (list "" '(0 default nil)) 
  339.   )
  340.  
  341. ;; Level 2 - keywords and builtin functions
  342. (setq rexx-font-lock-keywords-2
  343.   (append
  344.     rexx-font-lock-keywords-1
  345.     (list
  346.       (list
  347.     (concat
  348.       "\\<\\(a\\(ddress\\|rg\\)\\|break\\|call\\|d\\(o\\|rop\\)\\|"
  349.       "e\\(cho\\|lse\\|nd\\|xit\\)\\|i\\(f\\|nterpret\\terate\\)\\|"
  350.       "forever\\|leave\\|n\\(op\\|umeric\\)\\|o\\(ptions\\|therwise\\)\\|"
  351.       "p\\(arse\\|rocedure\\|u\\(sh\\|ll\\)\\)\\|queue\\|return\\|"
  352.       "s\\(ay\\|elect\\|hell\\|ignal\\)\\|t\\(hen\\|o\\|race\\)\\|"
  353.       "u\\(ntil\\|pper\\)\\|wh\\(en\\|ile\\)\\)\\>"
  354.       )
  355.     '(1 font-lock-keyword-face nil))
  356.       (list
  357.     (concat
  358.       "\\<\\("
  359.       "a\\(b\\(brev\\|s\\)\\|dd\\(lib\\|ress\\)\\)\\|"
  360.       "b\\(2c\\|it\\(c\\(hg\\|lr\\|omp\\)\\|or\\|set\\|tst\\|xor\\)\\)\\|"
  361.       "c\\(2\\(b\\|d\\|x\\)\\|ent\\(re\\|er\\)\\|"
  362.       "lose\\|o\\(mp\\(are\\|ress\\)\\|pies\\)\\)\\|"
  363.       "d\\(at\\(atype\\|e\\)\\|el\\(str\\|word\\)\\|igits\\)\\|"
  364.       "e\\(of\\|rrortext\\|x\\(port\\|ists\\)\\)\\|"
  365.       "f\\(orm\\|reespace\\|uzz\\)\\|get\\(clip\\|space\\)\\|hash\\|"
  366.       "i\\(mport\\|n\\(dex\\|sert\\)\\)\\|"
  367.       "l\\(astpos\\|e\\(ft\\|ngth\\)\\|ines\\)\\|"
  368.       "m\\(ax\\|in\\)\\|o\\(ffset\\|pen\\|verlay\\)\\|p\\(os\\|ragma\\)\\|"
  369.       "r\\(and\\(om\\|u\\)\\|e\\(ad\\(ch\\|ln\\)\\|mlib\\|verse\\)\\|ight\\)\\|"
  370.       "s\\(e\\(ek\\|tclip\\)\\|how\\|ign\\|ourceline||\pace\\|"
  371.       "t\\(\\orage\\|rip\\)\\|ub\\(str\\|word\\)\\|ymbol\\)\\|"
  372.       "t\\(ime\\|\\(r\\(a\\(ce\\|nslate\\)\\|im\\|unc\\)\\)\\)\\|"
  373.       "upper\\|v\\(alue\\|erify\\)\\|"
  374.       "w\\(ord\\(\\|index\\lengh\\|s\\)\\|rite\\(ch\\|ln\\)\\)\\|"
  375.       "x\\(2c\\|range\\)"
  376.       "\\)\\>"
  377.       )
  378.     '(1 font-lock-function-name-face nil))
  379.       )
  380.     )
  381.   )
  382.  
  383. ;; Level 3 -  ports
  384. (setq rexx-font-lock-keywords-3
  385.   (append
  386.     rexx-font-lock-keywords-2
  387.     (list
  388.       ;; ports
  389.       (list
  390.     "address *\\(\\<\\w*\\>\\)" '(1 font-lock-variable-name-face nil))
  391.       ;; user function names
  392.       (list
  393.     "^\\(\\<.*\\>\\):" '(1 font-lock-type-face nil))
  394.       )
  395.     
  396.     )
  397.   )
  398.  
  399. (setq rexx-font-lock-keywords rexx-font-lock-keywords)
  400.  
  401.  
  402. (defun rexx-mode ()
  403. "Major mode for editing REXX code.
  404. \\{rexx-mode-map}
  405.  
  406. Variables controlling indentation style:
  407.  rexx-indent
  408.     The basic indentation for do-blocks.
  409.  rexx-end-indent
  410.     The relative offset of the \"end\" statement. 0 places it in the
  411.     same column as the statements of the block. Setting it to the same
  412.     value as rexx-indent places the \"end\" under the do-line.
  413.  rexx-cont-indent
  414.     The indention for lines following \"then\", \"else\" and \",\"
  415.     (continued) lines.
  416.  rexx-tab-always-indent
  417.     Non-nil means TAB in REXX mode should always reindent the current 
  418.     line, regardless of where in the line the point is when the TAB
  419.     command is used.
  420.  
  421. If you have set rexx-end-indent to a nonzero value, you probably want to
  422. remap RETURN to rexx-indent-newline-indent. It makes sure that lines
  423. indents correctly when you press RETURN.
  424.  
  425. An extensive abbrevation table consisting of all the keywords of REXX are
  426. supplied. Expanded keywords are converted into upper case making it
  427. easier to distinguish them. To use this feature the buffer must be in
  428. abbrev-mode. (See example below.)
  429.  
  430. Turning on REXX mode calls the value of the variable rexx-mode-hook with
  431. no args, if that value is non-nil.
  432.  
  433. For example:
  434. (setq rexx-mode-hook '(lambda ()
  435.             (setq rexx-indent 4)
  436.             (setq rexx-end-indent 4)
  437.             (setq rexx-cont-indent 4)
  438.             (local-set-key \"\\C-m\" 'rexx-indent-newline-indent)
  439.             (abbrev-mode 1)
  440.             ))
  441.  
  442. will make the END aligned with the DO/SELECT. It will indent blocks and
  443. IF-statenents four steps and make sure that the END jumps into the
  444. correct position when RETURN is pressed. Finaly it will use the abbrev
  445. table to convert all REXX keywords into upper case."
  446.   (interactive)
  447.   (kill-all-local-variables)
  448.   (use-local-map rexx-mode-map)
  449.   (set-syntax-table rexx-mode-syntax-table)
  450.   (setq major-mode 'rexx-mode)
  451.   (setq mode-name "REXX")
  452.   (setq local-abbrev-table rexx-mode-abbrev-table)
  453.   (make-local-variable 'case-fold-search)
  454.   (setq case-fold-search t)
  455.   (make-local-variable 'paragraph-start)
  456.   (setq paragraph-start (concat "^$\\|" page-delimiter))
  457.   (make-local-variable 'paragraph-separate)
  458.   (setq paragraph-separate paragraph-start)
  459.   (make-local-variable 'paragraph-ignore-fill-prefix)
  460.   (setq paragraph-ignore-fill-prefix t)
  461.   (make-local-variable 'indent-line-function)
  462.   (setq indent-line-function 'rexx-indent-command)
  463.   (make-local-variable 'parse-sexp-ignore-comments)
  464.   (setq parse-sexp-ignore-comments t)
  465.   (make-local-variable 'comment-start)
  466.   (setq comment-start "/*")
  467.   (make-local-variable 'comment-end)
  468.   (setq comment-end "*/")
  469.   (make-local-variable 'comment-column)
  470.   (setq comment-column 32)
  471.   (make-local-variable 'comment-start-skip)
  472.   (setq comment-start-skip "/\\*+ *")
  473.   (make-local-variable 'comment-indent-function)
  474.   (setq comment-indent-function 'rexx-comment-indent)
  475.  
  476.   ;; font-lock vars
  477.   (message "setting font-lock")
  478.   (make-local-variable 'font-lock-defaults)
  479.   (setq font-lock-defaults 
  480.     '((rexx-font-lock-keywords-1 rexx-font-lock-keywords-2
  481.     rexx-font-lock-keywords-3) nil t ((?_ . "w"))
  482.        )
  483.     )
  484.   (require 'font-lock)
  485.  
  486.   (run-hooks 'rexx-mode-hook))
  487.  
  488.  
  489. (defun rexx-indent-command (&optional whole-exp)
  490.   "Indent the current line as REXX code."
  491.   (interactive "P")
  492.   (if whole-exp
  493.     (let ((shift-amt (rexx-indent-line))
  494.        beg
  495.        end)
  496.       (save-excursion
  497.       (if rexx-tab-always-indent
  498.           (beginning-of-line))
  499.       (setq beg (point))
  500.       (forward-sexp 1)
  501.       (setq end (point))
  502.       (goto-char beg)
  503.       (forward-line 1)
  504.       (setq beg (point)))
  505.     (if (> end beg)
  506.         (indent-code-rigidly beg end shift-amt)))
  507.     (if (and (not rexx-tab-always-indent)
  508.          (save-excursion
  509.           (skip-chars-backward " \t")
  510.           (not (bolp))))
  511.     (insert-tab)
  512.       (rexx-indent-line))))
  513.  
  514. (defun rexx-indent-line ()
  515.   "Indent the current line as REXX code.
  516. Return the amount the indentation changed by."
  517.   (let ((indent (rexx-calc-indent))
  518.     beg
  519.     shift-amt
  520.         (pos (- (point-max) (point))))
  521.     (beginning-of-line)
  522.     (setq beg (point))
  523.     (cond ((eq indent nil) (setq indent (current-indentation)))
  524.       ((eq indent t) (setq indent (rexx-calculate-indent-within-comment)))
  525.       ((looking-at "[ \t]*#") (setq indent 0))
  526.       (t (skip-chars-forward " \t")
  527.          (if (listp indent) (setq indent (car indent)))
  528.           ;; /* Språkspecifik kod! */
  529.          (if (looking-at "end") (setq indent (- indent rexx-end-indent)))))
  530.     (skip-chars-forward " \t")
  531.     (setq shift-amt (- indent (current-column)))
  532.     (if (zerop shift-amt)
  533.     (if (> (- (point-max) pos) (point))
  534.         (goto-char (- (point-max) pos)))
  535.       (delete-region beg (point))
  536.       (indent-to indent)
  537.       (if (> (- (point-max) pos) (point))
  538.       (goto-char (- (point-max) pos))))
  539.     shift-amt))
  540.  
  541. (defun rexx-calc-indent ()
  542.   "Return the appropriate indentation for this line as an int."
  543.   (save-excursion
  544.     (beginning-of-line)
  545.     (let ((block (rexx-find-environment))
  546.       beg
  547.       state
  548.       indent)
  549.       (save-excursion (setq state (rexx-inside-comment-or-string)))
  550.       (cond ((or (nth 3 state) (nth 4 state))
  551.          (nth 4 state))    ;; Inside a comment or string
  552.         (t    
  553.          ;; Find line to indent current line after.
  554.          (rexx-backup-to-noncomment 1)
  555.          (beginning-of-line)
  556.          (setq beg (rexx-find-environment))
  557.          (while (> beg block)
  558.            (goto-char beg)
  559.            (beginning-of-line)
  560.            (setq beg (rexx-find-environment)))
  561.  
  562.          (if (> (point) block)         
  563.          ;; Check to see if we shall make a special indention
  564.          (if (looking-at rexx-special-regexp)
  565.              (+ (current-indentation) rexx-cont-indent)
  566.            ;; If not, find the basic indention by stepping
  567.            ;; by all special indented lines.
  568.            (progn
  569.              (setq indent (current-indentation))
  570.              (rexx-backup-to-noncomment 1)
  571.              (beginning-of-line)
  572.              (while (looking-at rexx-special-regexp)
  573.                (setq indent (current-indentation))
  574.                (rexx-backup-to-noncomment 1)
  575.                (beginning-of-line))
  576.              indent))
  577.            (if (= 1 block)
  578.            0
  579.          ;; Indent after the do-line.
  580.          (progn
  581.            (goto-char block)
  582.            (+ (current-indentation) rexx-indent)))))))))
  583.  
  584. (defun rexx-backup-to-noncomment (lim)
  585.   "Backup the point to the previous noncomment REXX line."
  586.   (let (stop)
  587.     (while (not stop)
  588.       (skip-chars-backward " \t\n\f" lim)
  589.       (if (and (>= (point) (+ 2 lim))
  590.            (save-excursion
  591.          (forward-char -2)
  592.          (looking-at "\\*/")))
  593.       (search-backward "/*" lim 'move)
  594.     (setq stop t)))
  595.     (>= (point) lim)))
  596.  
  597. (defun rexx-find-environment ()
  598.   "Return the position of the corresponding \"do\" or \"select\".
  599. If none found, return the beginning of buffer."
  600.   (save-excursion
  601.     (let ((do-level 1)
  602.       (cont t)
  603.       state)
  604.       (while (and cont (not (zerop do-level)))
  605.     (setq cont (re-search-backward "\\b\\(do\\|select\\|end\\)\\b" 1 t))
  606.     (save-excursion (setq state (rexx-inside-comment-or-string)))
  607.     (setq do-level (+ do-level
  608.               (cond ((or (nth 3 state) (nth 4 state)) 0)
  609.                 ((looking-at "do") -1)
  610.                 ((looking-at "select") -1)
  611.                 ((looking-at "end") +1)
  612.                 (t 0)))))
  613.  
  614.       (if cont (point) 1))))
  615.  
  616. (defun rexx-calculate-indent-within-comment ()
  617.   "Return the indentation amount for line, assuming that
  618. the current line is to be regarded as part of a block comment."
  619.   (let (end star-start)
  620.     (save-excursion
  621.       (beginning-of-line)
  622.       (skip-chars-forward " \t")
  623.       (setq star-start (= (following-char) ?\*))
  624.       (skip-chars-backward " \t\n")
  625.       (setq end (point))
  626.       (beginning-of-line)
  627.       (skip-chars-forward " \t")
  628.       (and (re-search-forward "/\\*[ \t]*" end t)
  629.        star-start
  630.        (goto-char (1+ (match-beginning 0))))
  631.       (current-column))))
  632.  
  633. (defun rexx-comment-indent ()
  634.   (if (looking-at "^/\\*")
  635.       0                ;Existing comment at bol stays there.
  636.     (save-excursion
  637.       (skip-chars-backward " \t")
  638.       (max (1+ (current-column))    ;Else indent at comment column
  639.        comment-column))))    ; except leave at least one space.
  640.  
  641. (defun rexx-find-matching-do ()
  642.   "Set mark, look for the \"do\" or \"select\" for the present block."
  643.   (interactive)
  644.   (set-mark-command nil)
  645.   (beginning-of-line)
  646.   (goto-char (rexx-find-environment)))
  647.  
  648. (defun rexx-check-expansion ()
  649.   "If abbrev was made within a comment or a string, de-abbrev!"
  650.   (let ((state (rexx-inside-comment-or-string)))
  651.     (if (or (nth 3 state) (nth 4 state))
  652.     (unexpand-abbrev))))
  653.  
  654. (defun rexx-inside-comment-or-string ()
  655.   "Check if the point is inside a comment or a string.
  656. It returns the state from parse-partial-sexp for the search that
  657. terminated on the points position"
  658.   (let ((origpoint (point))
  659.     state)
  660.     (save-excursion 
  661.       (goto-char 1)
  662.       (while (> origpoint (point))
  663.     (setq state (parse-partial-sexp (point) origpoint 0))))
  664.     state))
  665.  
  666. (defun rexx-indent-and-newline ()
  667.   "New newline-and-indent which expands abbrevs before running
  668. a regular newline-and-indent."
  669.   (interactive)
  670.   (if abbrev-mode 
  671.       (expand-abbrev))
  672.   (newline-and-indent))
  673.  
  674. (defun rexx-indent-newline-indent ()
  675.   "New newline-and-indent which expands abbrevs and indent the line
  676. before running a regular newline-and-indent."
  677.   (interactive)
  678.   (rexx-indent-command)
  679.   (if abbrev-mode 
  680.       (expand-abbrev))
  681.   (newline-and-indent))
  682.